package com.example.springaop.brokerdemo2;

import lombok.val;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;
import java.sql.SQLOutput;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Hua YY
 * Date: 2024-12-30
 * Time: 11:25
 */
public class CGLIBInterceptor implements MethodInterceptor {
    //目标对象，被代理的对象
    private Object target;
    public CGLIBInterceptor(Object target){
        this.target = target;
    }
    @Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        System.out.println("我是中介，开始代理");
        //调用方法（反射机制）
        Object retVal = method.invoke(target, objects);
        //代理增强内容
        System.out.println("我是中介，代理结束");
        return retVal;
    }
}
